<template>
  <div class="app-container">
    <!-- 查询 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item prop="queryParams.processName">
        <el-input
          icon="el-icon-search"
          v-model="queryParams.processName"
          placeholder="请输入工艺流程名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" size="mini" @click="handleQuery"
          >查询</el-button
        >
      </el-form-item>
    </el-form>

    <el-row style="margin-top: 20px">
      <el-button type="success" @click="handleAdd">新建</el-button>
    </el-row>

    <!-- 列表 processList-->
    <el-table
      class="tables"
      v-loading="loading"
      :data="processList"
      @selection-change="handleSelectionChange"
      style="margin-top: 30px"
      border
    >
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="工艺流程编号" align="center" prop="processNo" />
      <el-table-column label="工艺流程名称" align="center" prop="processName" />
      <el-table-column label="工序数量" align="center" prop="processQuantity" />
      <el-table-column
        label="工艺流程"
        align="center"
        prop="technologicalProcess"
      />
      <el-table-column label="创建角色" align="center" prop="createRole" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:process:edit']"
            >编辑

            <!-- (scope.row) -->
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:process:remove']"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="checks(scope.row)"
            v-hasPermi="['base:process:edit']"
            >查看</el-button
          >
          <!-- v-hasPermi="['base:process:remove']" 查看 ， 删除 修改 掉的接口 -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listProcess,
  getProcess,
  delProcess,
  addProcess,
  updateProcess,
} from "@/api/base/process";

export default {
  name: "Process",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工艺流程表格数据
      processList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        processNo: null,
        processName: null,
        processQuantity: null,
        technologicalProcess: null,
        createRole: null,
      },

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" },
        ],
        createRole: [
          { required: true, message: "创建角色不能为空", trigger: "blur" },
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" },
        ],
      },
      input: "",
    };
  },
  created() {
    this.getList();
    // this.methods();
  },

  methods: {
    /** 查询工艺流程列表 */
    getList() {
      this.loading = true;
      listProcess(this.queryParams).then((response) => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // this.open = true;
      // this.title = "添加工艺流程";
      this.$router.push({ path: "/base/index" });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        processNo: null,
        processName: null,
        processQuantity: null,
        technologicalProcess: null,
        createBy: null,
        createRole: null,
        createTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.processName = this.queryParams.processName;
      this.getList();
    },
    /** 重置按钮操作 */
    // resetQuery() {
    //   this.resetForm("queryForm");
    //   // this.handleQuery();
    // },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    // 查看
    checks(item) {
      this.reset();
      this.$router.push({
        path: "/base/CheckViews",
        query: {
          id: item.id,
        },
      });
    },

    /** 修改按钮操作 */
    handleUpdate(item) {
      this.reset();
      this.$router.push({
        path: "/base/edit",
        query: {
          id: item.id,
        },
      });
    },
    /** 提交按钮 */
    // submitForm() {
    //   this.$refs["queryForm"].validate((valid) => {
    //     if (valid) {
    //       if (this.form.id != null) {
    //         updateProcess(this.form).then((response) => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addProcess(this.form).then((response) => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除工艺流程编号为"' + ids + '"的数据项？')
        .then(function () {
          return delProcess(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    // handleExport() {
    //   this.download(
    //     "base/process/export",
    //     {
    //       ...this.queryParams,
    //     },
    //     `process_${new Date().getTime()}.xlsx`
    //   );
    // },
  },
};
</script>
<style scoped></style>
